package test.service.serviceCCapp;

import com.ceshi.entity.CcToken;
import okhttp3.*;
import org.testng.Assert;
import test.util.CcTokenDB;
import test.util.LogPrinting;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import static org.hamcrest.core.StringContains.containsString;
import static org.junit.Assert.assertThat;

public class UserVideoUploadList {
    /**
     * 用户视频上传列表
     * @return
     * @throws IOException
     */
    public static String userVideoUploadList() throws IOException {

        //获取当前时间转换为字符串
        SimpleDateFormat sdf = new SimpleDateFormat("MMddHHmm");
        String strDate = sdf.format(new Date());
        List<CcToken> ccTokenList= CcTokenDB.getAll();
        String userId = ccTokenList.get(0).getUserIdToken();
        LogPrinting.log("userId",userId);
        String token = ccTokenList.get(0).getToken();
        LogPrinting.log("token",token);

        OkHttpClient client = new OkHttpClient().newBuilder().build();
        Request request = new Request.Builder()
                .url("https://ugc.ccdev.lerjin.com/video/upload/list?page=0&size=10")
                .method("GET", null)
                .addHeader("token", token)
                .addHeader("module", "ugc")
                .addHeader("userId", userId)
                .build();

        LogPrinting.log("request数据",request);
        Response response = client.newCall(request).execute();

        // 获取头部
        Headers rsultHeaders = response.headers();
        // 获取身体信息
        String rsultBody = response.body().string();
        LogPrinting.log("response数据",rsultBody);

        //断言是否包含
        assertThat(rsultBody.replace("\"", ""),containsString("first:true"));
        return null;
    }
}
